import "./header.js"
import {querystring} from "./tools.js"

let {filmId} = querystring.parse(location.search);
if(filmId){
  $.ajax({
    url:"/api/cinemas/films/"+filmId,
    type:"get",
    success:function(data){
      let str = data.map((item) => {
        return generateCinemas(filmId,item.cinemas);
      }).join("");
      $(".cinemas-list").append(str);
    }
  });
}else{
  $.ajax({
    url:"/api/cinemas",
    type:"get",
    success:function(data){
      console.log(data);
      let str = data.rows.map((item) => {
        
        return generateCinemas(filmId,item);
      }).join("");
      $(".cinemas-list").append(str);
    }
  });
}


const generateCinemas = function(filmId,data){
  return `
      <div class="cinema-cell">
      <div class="cinema-info">
        <a href="/screens" class="cinema-name" data-act="cinema-name-click" ">${data.name}</a>
        <p class="cinema-address">${data.addr}</p>
      </div>
      <div class="buy-btn">
        <a href="/screens.html?filmId=${filmId||''}&cinemaId=${data._id}">选座购票</a>
      </div>
    </div>
      `
}